<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>jsunit.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_testing_jsunit.js.html">jsunit.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2007 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Utilities for working with JsUnit.  Writes out the JsUnit file
<a name="line17"></a> * that needs to be included in every unit test.
<a name="line18"></a> *
<a name="line19"></a> * Testing code should not have dependencies outside of goog.testing so as to
<a name="line20"></a> * reduce the chance of masking missing dependencies.
<a name="line21"></a> *
<a name="line22"></a> */
<a name="line23"></a>
<a name="line24"></a>goog.provide(&#39;goog.testing.jsunit&#39;);
<a name="line25"></a>
<a name="line26"></a>goog.require(&#39;goog.testing.TestCase&#39;);
<a name="line27"></a>goog.require(&#39;goog.testing.TestRunner&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * Base path for JsUnit app files, relative to Closure&#39;s base path.
<a name="line32"></a> * @type {string}
<a name="line33"></a> */
<a name="line34"></a>goog.testing.jsunit.BASE_PATH =
<a name="line35"></a>    &#39;../../third_party/java/jsunit/core/app/&#39;;
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * Filename for the core JS Unit script.
<a name="line40"></a> * @type {string}
<a name="line41"></a> */
<a name="line42"></a>goog.testing.jsunit.CORE_SCRIPT =
<a name="line43"></a>    goog.testing.jsunit.BASE_PATH + &#39;jsUnitCore.js&#39;;
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>/**
<a name="line47"></a> * @define {boolean} If this code is being parsed by JsTestC, we let it disable
<a name="line48"></a> * the onload handler to avoid running the test in JsTestC.
<a name="line49"></a> */
<a name="line50"></a>goog.testing.jsunit.AUTO_RUN_ONLOAD = true;
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>(function() {
<a name="line54"></a>
<a name="line55"></a>  // Store a reference to the window&#39;s timeout so that it can&#39;t be overridden
<a name="line56"></a>  // by tests.
<a name="line57"></a>  var realTimeout = window.setTimeout;
<a name="line58"></a>
<a name="line59"></a>  // Check for JsUnit&#39;s test runner (need to check for &gt;2.2 and &lt;=2.2)
<a name="line60"></a>  if (top[&#39;JsUnitTestManager&#39;] || top[&#39;jsUnitTestManager&#39;]) {
<a name="line61"></a>    // Running inside JsUnit so add support code.
<a name="line62"></a>    var path = goog.basePath + goog.testing.jsunit.CORE_SCRIPT;
<a name="line63"></a>    document.write(&#39;&lt;script type=&quot;text/javascript&quot; src=&quot;&#39; +
<a name="line64"></a>                  path + &#39;&quot;&gt;&lt;/&#39; + &#39;script&gt;&#39;);
<a name="line65"></a>
<a name="line66"></a>  } else {
<a name="line67"></a>
<a name="line68"></a>    // Create a test runner.
<a name="line69"></a>    var tr = new goog.testing.TestRunner();
<a name="line70"></a>
<a name="line71"></a>    // Export it so that it can be queried by Selenium and tests that use a
<a name="line72"></a>    // compiled test runner.
<a name="line73"></a>    goog.exportSymbol(&#39;G_testRunner&#39;, tr);
<a name="line74"></a>    goog.exportSymbol(&#39;G_testRunner.initialize&#39;, tr.initialize);
<a name="line75"></a>    goog.exportSymbol(&#39;G_testRunner.isInitialized&#39;, tr.isInitialized);
<a name="line76"></a>    goog.exportSymbol(&#39;G_testRunner.isFinished&#39;, tr.isFinished);
<a name="line77"></a>    goog.exportSymbol(&#39;G_testRunner.isSuccess&#39;, tr.isSuccess);
<a name="line78"></a>    goog.exportSymbol(&#39;G_testRunner.getReport&#39;, tr.getReport);
<a name="line79"></a>    goog.exportSymbol(&#39;G_testRunner.getRunTime&#39;, tr.getRunTime);
<a name="line80"></a>    goog.exportSymbol(&#39;G_testRunner.getNumFilesLoaded&#39;, tr.getNumFilesLoaded);
<a name="line81"></a>    goog.exportSymbol(&#39;G_testRunner.setStrict&#39;, tr.setStrict);
<a name="line82"></a>    goog.exportSymbol(&#39;G_testRunner.logTestFailure&#39;, tr.logTestFailure);
<a name="line83"></a>
<a name="line84"></a>    // Export debug as a global function for JSUnit compatibility.  This just
<a name="line85"></a>    // calls log on the current test case.
<a name="line86"></a>    if (!goog.global[&#39;debug&#39;]) {
<a name="line87"></a>      goog.exportSymbol(&#39;debug&#39;, goog.bind(tr.log, tr));
<a name="line88"></a>    }
<a name="line89"></a>
<a name="line90"></a>    // If the application has defined a global error filter, set it now.  This
<a name="line91"></a>    // allows users who use a base test include to set the error filter before
<a name="line92"></a>    // the testing code is loaded.
<a name="line93"></a>    if (goog.global[&#39;G_errorFilter&#39;]) {
<a name="line94"></a>      tr.setErrorFilter(goog.global[&#39;G_errorFilter&#39;]);
<a name="line95"></a>    }
<a name="line96"></a>
<a name="line97"></a>    // Add an error handler to report errors that may occur during
<a name="line98"></a>    // initialization of the page.
<a name="line99"></a>    window.onerror = function(error, url, line) {
<a name="line100"></a>      if (typeof error == &#39;object&#39;) {
<a name="line101"></a>        // Webkit started passing an event object as the only argument to
<a name="line102"></a>        // window.onerror.  It doesn&#39;t contain an error message, url or line
<a name="line103"></a>        // number.  We therefore log as much info as we can.
<a name="line104"></a>        if (error.target &amp;&amp; error.target.tagName == &#39;SCRIPT&#39;) {
<a name="line105"></a>          tr.logError(&#39;UNKNOWN ERROR: Script &#39; + error.target.src);
<a name="line106"></a>        } else {
<a name="line107"></a>          tr.logError(&#39;UNKNOWN ERROR: No error information available.&#39;);
<a name="line108"></a>        }
<a name="line109"></a>      } else {
<a name="line110"></a>        tr.logError(&#39;JS ERROR: &#39; + error + &#39;\nURL: &#39; + url + &#39;\nLine: &#39; + line);
<a name="line111"></a>      }
<a name="line112"></a>    };
<a name="line113"></a>
<a name="line114"></a>    // Create an onload handler, if the test runner hasn&#39;t been initialized then
<a name="line115"></a>    // no test has been registered with the test runner by the test file.  We
<a name="line116"></a>    // then create a new test case and auto discover any tests in the global
<a name="line117"></a>    // scope. If this code is being parsed by JsTestC, we let it disable the
<a name="line118"></a>    // onload handler to avoid running the test in JsTestC.
<a name="line119"></a>    if (goog.testing.jsunit.AUTO_RUN_ONLOAD) {
<a name="line120"></a>      window.onload = function() {
<a name="line121"></a>        // Wait 500ms longer so that we don&#39;t interfere with Selenium.
<a name="line122"></a>        realTimeout(function() {
<a name="line123"></a>          if (!tr.initialized) {
<a name="line124"></a>            var test = new goog.testing.TestCase(document.title);
<a name="line125"></a>            test.autoDiscoverTests();
<a name="line126"></a>            tr.initialize(test);
<a name="line127"></a>          }
<a name="line128"></a>          tr.execute();
<a name="line129"></a>        }, 500);
<a name="line130"></a>        window.onload = null;
<a name="line131"></a>      };
<a name="line132"></a>    }
<a name="line133"></a>  }
<a name="line134"></a>})();
</pre>


</body>
</html>
